<template>
    <el-drawer
        v-model="isShow"
        title="历史信访记录"
        :destroy-on-close="true"
        size="50%"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        :show-close="false"
    >
        <el-alert :title="title" type="success" class="mb-2" :closable="false"/>

        <el-table
            :data="visitHistoryTableData"
            v-loading="loading"
            show-overflow-tooltip
            border
        >
            <el-table-column type="index"/>
            <el-table-column label="接待单位" prop="unitName"/>
            <el-table-column label="接待场所" prop="policeareaId"/>
            <el-table-column label="执勤法警" prop="adduserId"/>
            <el-table-column label="来访人" prop="name"/>
            <el-table-column label="来访日期" prop="checkintime"/>
            <el-table-column label="信访情况" prop="checkininfo"/>
        </el-table>

        <!--        <pagination-->
        <!--            v-show="total > 0"-->
        <!--            v-model:page="paging.pageNum"-->
        <!--            v-model:limit="paging.pageSize"-->
        <!--            :total="total"-->
        <!--            @pagination="getList"-->
        <!--        />-->

        <template #footer>
            <el-button @click="changeShowStatus">关闭</el-button>
        </template>
    </el-drawer>
</template>

<script setup>
// 抽屉显示状态
import {getVisitHistoryApi} from '@/api/RegisterVisit/RegisterVisit.js';
import PageEnum from '@/enum/PageEnum.js';

const isShow = ref(false);
const loading = ref(false)
const total = ref(0)
const paging = ref({
    // 页码
    pageNum: 1,
    // 分页数量
    pageSize: PageEnum.SIZE
});
// 身份证 ID
const idCard = ref('')
const visitHistoryTableData = ref([])
const title = ref('')

// 变更显示状态
const changeShowStatus = () => {
    isShow.value = !isShow.value
    if (!isShow.value) {
        idCard.value = '';
    }
}

const showVisitHistory = async (id) => {
    changeShowStatus()
    idCard.value = id;
    await getList();
}
defineExpose({showVisitHistory});

// 获取来访历史数据列表
const getList = async () => {
    loading.value = true;
    const res = await getVisitHistoryApi({
        sfzId: idCard.value
    }, paging.value)
    // total.value = res.data;
    visitHistoryTableData.value = res.data;
    title.value = `共计 [ ${res.data.length} ] 次来访记录`
    loading.value = false;
    console.log('getVisitHistoryHandler', res)
}

</script>

<style scoped lang="scss">

</style>